from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QLabel, QVBoxLayout, QPushButton, QHBoxLayout
from PyQt5.QtCore import pyqtSignal, Qt


class DescDialog(QWidget):
    failDialogBtnOkSig = pyqtSignal()

    desc = ("<html>"
            "<body>"
            "<p>游戏说明</p>"
            "<p>1.按开始按钮或者空格键开始游戏</p>"
            "<p>2.方向键控制移动方向</p>"
            "<p>3.空格键控制游戏暂停</p>"
            "</body>"
            "</html>")

    def __init__(self):
        super().__init__()
        self.setAttribute(Qt.WA_DeleteOnClose | Qt.WA_QuitOnClose)
        self.setWindowTitle("snake")
        # self.setFixedSize(250, 200)

        self.vl = QVBoxLayout()
        self.hl = QHBoxLayout()
        self.logo = QPixmap("img/start.jpg")
        self.logo_label = QLabel()
        self.logo_label.setPixmap(self.logo)
        self.hl.setAlignment(Qt.AlignCenter)
        self.hl.addWidget(self.logo_label)

        self.msg = QLabel()
        self.msg.setText(self.desc)
        self.msg.setWordWrap(True)
        self.btnOk = QPushButton("确定")

        self.vl.addLayout(self.hl)
        self.vl.addWidget(self.msg)
        self.vl.addWidget(self.btnOk)

        self.setLayout(self.vl)

        self.btnOk.clicked.connect(self.handleBtnOk)

    def handleBtnOk(self):
        self.close()
